import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components'
import { DNavBar, DLookImages } from '@/components'
import './enterprisedetail.scss'
import http from '@/api'
const itembg = require('../assets/people_right.png')

export default class EnterpriseDetail extends Component {

    constructor(props) {
        super(props)
        this.state = {
            item: {},
            img1: '',
            img2: '',
            img3: '',
            img4: '',
            status: '',
            companycar: {
                itemStatus: false,
                itemUrl: ''
            }
        }
    }
    componentWillMount() {
        this.getEntinfo()
    }
    getEntinfo() {
        let { id = "a95ca35c-f77e-4c34-8f33-ceeb57b9134f" } = this.$router.params
        http.getEntinfo({ id: `${id}` }).then(res => {
            if (!res.fileList) {
                return
            }
            let { img1, img2, img3, img4 } = this.state
            res.fileList.map(item => {
                if (item.cfType === '1') {
                    img1 = item.cfFileUrl
                }
                if (item.cfType === '2') {
                    img2 = item.cfFileUrl
                }
                if (item.cfType === '3') {
                    img3 = item.cfFileUrl
                }
                if (item.cfType === '4') {
                    img4 = item.cfFileUrl
                }

            })
            this.setState({
                item: res,
                img1,
                img2,
                img3,
                img4
            })
        })
    }

    onLookHandle(url) {
        if (window.bridge) {
            let _images = [], i = 0
            _images.push(url)
            window.bridge.callHandler('previewPhoto', { "index": i, "images": _images }, function responseCallback() { })
        } else {
            this.setState({
                companycar: {
                    ...this.state.companycar,
                    itemStatus: true,
                    itemUrl: url
                }
            })
        }
    }

    onLookItem() {
        this.setState({
            companycar: {
                ...this.state.companycar,
                itemStatus: false,
                itemUrl: ''
            }
        })
    }

    render() {
        const {
            item,
            img1,
            img2,
            img3,
            img4,
            status,
            companycar
        } = this.state
        return (
            <View className='b_enterprisedetail'>
                <DNavBar title='企业认证'></DNavBar>
                <View className='b_enterprisedetail__box'>
                    <View className="b_enterprisedetail__tips">
                        <Text>请耐心等待，平台管理员将会在3个工作日内审核您的申请</Text>
                    </View>

                    <View className="b_enterprisedetail__info">
                        <View className="item_title">
                            <Text className="item_title__left">企业名称</Text>
                            <Text className="item_title__right">{item.entName || '---'}</Text>
                        </View>
                        <View className="item_title">
                            <Text className="item_title__left">法人代表</Text>
                            <Text className="item_title__right">{item.entOwner || '---'}</Text>
                        </View>
                        <View className="item_title">
                            <Text className="item_title__left">所在区域</Text>
                            <Text className="item_title__right">{item.entDis || '---'}</Text>
                        </View>
                        <View className="item_title">
                            <Text className="item_title__left">企业地址</Text>
                            <Text className="item_title__right">{item.entAddr || '---'}</Text>
                        </View>
                        <View className="item_title">
                            <Text className="item_title__left">企业性质</Text>
                            <Text className="item_title__right">{item.entAtt || '---'}</Text>
                        </View>
                    </View>
                </View>
                <View className='b_enterprisedetail__images'>
                    <Text className='b_enterprisedetail__images_title'>资料图片</Text>
                    <View className="b_enterprisedetail__images_enterpris">
                        <View className='b_enterprisedetail__images_enterpris_item'>
                            <Text className='item_title'>企业营业执照</Text>
                            {
                                img1 && <Image src={img1} className='item_image' onClick={this.onLookHandle.bind(this, img1)}></Image>
                            }
                        </View>
                        <View className="b_enterprisedetail__images_enterpris_item">
                            <Text className="item_title">企业门店照片</Text>
                            {
                                img4 && <Image src={img4} className='item_image' onClick={this.onLookHandle.bind(this, img4)}></Image>
                            }
                        </View>
                        <View className="b_enterprisedetail__images_enterpris_item">
                            <Text className="item_title">法人身份证</Text>
                            <View className='item_image__list'>
                                {
                                    img2 && <View className='item_image'>
                                        <Image src={img2} className='item_bigimage' onClick={this.onLookHandle.bind(this, img2)}></Image>
                                    </View>
                                }
                                {
                                    img3 && <View className='item_image'>
                                        <Image src={img3} className='item_bigimage' onClick={this.onLookHandle.bind(this, img3)}></Image>
                                    </View>
                                }

                            </View>
                        </View>
                    </View>
                </View>
                <DLookImages status={companycar.itemStatus} url={companycar.itemUrl} onLookHandle={this.onLookItem.bind(this)}></DLookImages>
            </View>
        )
    }
}